package com.example.demo.domain;

import cn.hutool.core.io.resource.ResourceUtil;
import com.itextpdf.kernel.colors.Color;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.font.PdfFont;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.InputStream;

@Data
@NoArgsConstructor
public class TextEntity {

    /**
     * 生成图片内容
     */
    private String text;
    /**
     * 文字大小
     */
    private float fontsize;
    /**
     * X轴间距
     */
    private float xStep;
    /**
     * Y轴间距
     */
    private float yStep;
    /**
     * 旋转角度
     */
    private float angle;
    /**
     * 文字透明度，取值 0~1之间
     */
    private float opacity;
    /**
     * 文字颜色
     */
    private Color color;
    /**
     * 字体
     */
    private PdfFont font;
    /**
     * awt颜色
     */
    private java.awt.Color awtColor;
    /**
     * 字体路径
     */
    private String fontPath = "font/simhei.ttf";


    public TextEntity(String text) {
        this.text = text;
        this.fontsize = 20f;
        this.xStep = 150;
        this.yStep = 150;
        this.angle = 40f;
        this.opacity = 0.3f;
        this.color = ColorConstants.LIGHT_GRAY;
    }

    public TextEntity(String text, float fontsize, float xStep, float yStep) {
        this.text = text;
        this.fontsize = fontsize;
        this.xStep = xStep;
        this.yStep = yStep;
        this.angle = 40f;
        this.opacity = 0.3f;
        this.color = ColorConstants.LIGHT_GRAY;
    }

    public TextEntity(String text, float fontsize, float xStep, float yStep, float angle, float opacity, Color color, PdfFont font) {
        this.text = text;
        this.fontsize = fontsize;
        this.xStep = xStep;
        this.yStep = yStep;
        this.angle = angle;
        this.opacity = opacity;
        this.color = color;
        this.font = font;
    }

    public InputStream readFont() {
        return ResourceUtil.getStreamSafe(fontPath);
    }

}
